package com.xdf.whiteaccount.utils;


/**
 * 2023年8月15日 12:02:20 chanchaw
 * 调整属性同 ResponseResult，主要是两个属性：success, message
 * @ClassName:JsonResult
 * @Description:TODO
 * @Author:chanchaw
 * @Date:2019-12-07 19:38
 * @Version:1.0
 **/
public class JsonResult {
    private Integer code;
    private String message;
    private Object data;
    private boolean success;

    public JsonResult(ResultCode resultCode, Object data) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMsg();
        this.data = data;
    }

    public JsonResult() {
        this.code = 1;
        this.message = "";
        this.data = null;
        this.success = true;
    }

    public JsonResult(String message) {
        this.code = 1;
        this.success = true;
        this.message = message;
        this.data = null;
    }

    public JsonResult(Integer code, String message) {
        this.code = code;
        if(code.equals(1)) this.success = true;
        else this.success = false;
        this.message = message;
        this.data = null;
    }

    public JsonResult(Integer code,Object data, String message) {
        this.code = code;
        if(code.equals(1)) this.success = true;
        else success = false;
        this.message = message;
        this.data = data;
    }


    public static JsonResult ok() {
        JsonResult jr = new JsonResult();
        jr.success = true;
        return jr;
    }

    public static JsonResult ok(Object data) {
        JsonResult jr = new JsonResult(ResultCode.OK, data);
        jr.success = true;
        return jr;
    }
    public static JsonResult ok(Object data,String message) {
        JsonResult jr = new JsonResult(1, data, message);
        jr.success = true;
        return jr;
    }

    public static JsonResult error(ResultCode resultCode) {
        JsonResult jr = new JsonResult(resultCode, null);
        jr.success = false;
        return jr;
    }

    public static JsonResult error(String message) {
        JsonResult jr = new JsonResult(7777, message);
        jr.success = false;
        return jr;
    }

    public static JsonResult hold(String message) {
        return new JsonResult(77776, message);
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public Object getData() {
        return this.data;
    }

    @Override
    public String toString() {
        return "JsonResult{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}